package com.jifeng.api.crud.controller;

import com.jifeng.api.crud.entity.HeartEntity;
import com.jifeng.api.crud.service.HeartService;
import com.jifeng.api.utils.PageUtils;
import com.jifeng.api.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 
 *
 * @author jifeng
 * @email 1593140625@qq.com
 * @date 2020-09-05 09:24:03
 */
@RestController
@RequestMapping("crud/heart")
public class HeartController {
    @Autowired
    private HeartService heartService;

    /**
     * 入库
     */
    @PostMapping("/add")
    public R add(@RequestBody Map<String, Object> params){
       R rs= heartService.add(params);
        return rs;
    }

    /**
     * 更新入库数据
     */
    @PostMapping("/myUpdate")
    public R myUpdate(@RequestBody HeartEntity heartEntity){
        R rs= heartService.myUpdate(heartEntity);

        return rs;
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = heartService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		HeartEntity heart = heartService.getById(id);

        return R.ok().put("heart", heart);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody HeartEntity heart){
		heartService.save(heart);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody HeartEntity heart){
		heartService.updateById(heart);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		heartService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
